﻿using M_Quality.Domain;
using M_Quality.Repository.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace M_Quality.Repository.Impl
{
    public class BaseRawMaterialQualityRepository : BaseRepository<RawMaterialQuality>, IRawMaterialQualityRepository
    {
        public BaseRawMaterialQualityRepository(MyDbcontract myDbcontract) : base(myDbcontract)
        {
        }

        public async Task<int> AddRMQAsync(RawMaterialQuality Raw)
        {
            var num = await base.AddAsync(Raw);
            return num;
        }

        public async Task<List<RawMaterialQuality>> GetListAsync(string? RNumber, string? MNumber, string? State)
        {
            var gather = await base.GetAsync(x=>x.IsDeleted==false);
            if (RNumber != null)
            {
                gather = gather.Where(x=>x.MaterialNumber == RNumber).ToList();
            }
            if (MNumber != null)
            {
                gather = gather.Where(x=>x.QualityNumber == MNumber).ToList();
            }
            if(State != null)
            {
                gather = gather.Where(x=>x.QualityS == State).ToList();
            }
            return gather;
        }

        public async Task<int> RemoveRMQAsync(int id)
        {
            var aller = await base.GetModelAsync(id);
            aller.IsDeleted = true;
            var num = await base.UpdateAsync(aller);
            return num;
        }

        public async Task<RawMaterialQuality> ShowRMQAsync(int id)
        {
            var aller = await base.GetModelAsync(id);
            return aller;
        }

        public async Task<int> UpdRMQAsync(RawMaterialQuality Raw)
        {
            var num = await base.UpdateAsync(Raw);
            return num;
        }
    }
}
